<template>
  <div>
    <etable ref="eTable" v-show="currentState === 'normal'" :columns="columns"
            easySearchPlaceholder="文件名称" @btnClick="handClick" :tools="['easySearch','refresh']">
      <div slot="buttons">
        <Button type="primary" @click="handleAdd">新增</Button>
      </div>
    </etable>
    <downloadsaveupdate ref="su" @showTable="showTable" @hideTable="hideTable"></downloadsaveupdate>
  </div>
</template>

<script>
import etable from '@/components/easy-table/easy-table.vue'
import downloadsaveupdate from './download-save-update.vue'
import { deleteFile } from '../../../api/sys/download'
import { download } from '../../../api/sys/appendix'

export default {
  name: 'download',
  components: {
    etable,
    downloadsaveupdate
  },
  data: function () {
    return {
      url: 'sys/download/list?',
      currentState: 'normal',
      columns: [
        { title: '文件标题', key: 'title', align: 'center' },
        { title: '文件描述', key: 'mark', align: 'center' },
        { title: '上传人', key: 'username', align: 'center' },
        { title: '上传时间', key: 'createDate', align: 'center' },
        {
          title: '操作',
          key: 'handle',
          align: 'center',
          width: 140,
          options: ['edit', 'download', 'delete']
        }
      ]
    }
  },
  methods: {
    hideTable () {
      this.currentState = 'unNormal'
    },
    showTable () {
      this.currentState = 'normal'
      this.init()
    },
    handleAdd () {
      this.formItem = {}
      this.$refs['su'].showAdd()
    },
    handClick (name, params) {
      if (name === 'edit') {
        this.handleEdit(params)
      } else if (name === 'delete') {
        this.handleDelete(params)
      } else if (name === 'download') {
        download(params.row.uuid).then(res => {
        })
      }
    },
    handleDelete (param) {
      deleteFile(param.row.uuid).then(res => {
        this.init()
      })
    },
    handleEdit (param) {
      this.$refs['su'].showEdit(param.row.uuid)
    },
    init () {
      this.$refs['eTable'].init(this.url)
    }
  },
  mounted () {
    this.init()
  }
}
</script>

<style scoped>

</style>
